
//
//  ShiPinViewController.swift
//  新闻
//
//  Created by 芮京 on 2018/12/10.
//  Copyright © 2018 芮京. All rights reserved.
//

import UIKit
import Alamofire

class ShiPinViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    let VIDEO_PATH = "http://c.m.163.com/nc/video/list/V9LG4B3A0/y/0-20.html"
    var tab:UITableView?
    var arr:NSArray=[]
    var dicc:NSDictionary = [:]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //标题
        self.navigationItem.title="视频"
        
        tabb()
        VideoData()
    }
    //请求
    func VideoData(){
        Alamofire.request(VIDEO_PATH, method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
            if(response.error == nil){
                print("请求成功")
                //                print(response.result.value as Any)
                self.dicc = (response.result.value as? NSDictionary)!
                //                self.dictr = self.dicc.object(forKey: "data") as! NSDictionary
                self.arr = self.dicc.object(forKey: "V9LG4B3A0") as! NSArray
                
                self.tab?.reloadData()
                
            }else{
                print("+++++++Z++++++请求失败\(String(describing: response.error))")
            }
            //解析网址
        }
    }
    //表格
    func tabb () {
        tab=UITableView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
        tab?.delegate=self
        tab?.dataSource=self
        self.tab?.register( UINib(nibName: "ShipinTableViewCell", bundle: nil), forCellReuseIdentifier: "cells")
        self.view.addSubview(tab!)
        
    }
    //分行
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arr.count;
    }
    //行内容
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:ShipinTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cells") as! ShipinTableViewCell
        tableView.rowHeight=200
        let name:NSDictionary = arr[indexPath.row] as! NSDictionary
        let mod:ShipinModel = ShipinModel()
        mod.dicY = name
        cell.Shipin(mdoel: mod)
        return cell;
    }
    //行高
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 200
    }
    //跳转
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let jump = JumpViewController()
        let j :NSDictionary = arr[indexPath.row] as! NSDictionary
        jump.strr = j.object(forKey: "mp4_url") as! String
        self.navigationController?.pushViewController(jump, animated: true)
        
    }
}
